//
//  main.m
//  OC6_字典&集合课后作业color练习
//
//  Created by dllo on 15/10/31.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Color.h"
#import "ColorManager.h"


int main(int argc, const char * argv[]) {

    NSString *filePath = @"/Users/dllo/Desktop/DLS151034/OC6_字典&集合/OC6_字典&集合课后作业/OC6_字典&集合课后作业color练习/OC6_字典&集合课后作业color练习/File";
    
    NSString *str = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
    
    NSArray *arr = [str componentsSeparatedByString:@"\n"];
//    NSLog(@"%@",arr);
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    NSMutableArray *key = [NSMutableArray array];
    NSMutableArray *value = [NSMutableArray array];
    
    // 1, 字典管理
    for (NSInteger i = 0; i < arr.count; i++) {
        NSArray *temp = [[arr objectAtIndex:i] componentsSeparatedByString:@" #"];
        [dic setObject:[temp objectAtIndex:1] forKey:[temp objectAtIndex:0]];
        [key addObject:[temp objectAtIndex:0]];
    }
    
    // 2, 取出所有key, 升序排列
    
    [key sortUsingSelector:@selector(compare:)];
//    NSLog(@"%@", key);

    // 3,取出所有的value，按照排序后的key排列。
    
    for (NSInteger i = 0; i < key.count; i++) {
        [value addObject:[dic objectForKey:[key objectAtIndex:i]]];
    }
//    NSLog(@"%@", value);
    
    // 4,新字典管理

    
    ColorManager *colorList = [[ColorManager alloc] init];
    for (NSInteger i = 0; i < key.count; i++) {
        [colorList addColor:[key objectAtIndex:i] colorValue:[value objectAtIndex:i]];
    }
    
    [colorList test:@"A"];
    
    
    
    
    return 0;
}
